﻿using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using ReportWizard.Helpers;
using ReportWizard.DataAccess;
using ReportWizard.Properties;

namespace ReportWizard.Forms
{
    public partial class MainContainerForm : Form
    {
        public MainContainerForm()
        {
            InitializeComponent();
        }

        private void MainContainerFormLoad(object sender, EventArgs e)
        {
            CheckAdmin();
        }

        private void CheckAdmin()
        {
            if (!Globals.CurrentUser.Admin)
            {
                miStartGame.Visible = false;
            }
        }

        private void miCreateReport_Click(object sender, EventArgs e)
        {
            GeneratorForm generatorForm = new GeneratorForm(this);
            generatorForm.MdiParent = this;
            generatorForm.Show();
        }

        private void miSettings_Click(object sender, EventArgs e)
        {
            SettingsForm settingsForm = new SettingsForm();
            settingsForm.ShowDialog();
        }

        private void miArchive_Click(object sender, EventArgs e)
        {
            ArchiveForm archiveForm = new ArchiveForm(this);
            archiveForm.MdiParent = this;
            archiveForm.Show();
        }

        private void miStartGame_Click(object sender, EventArgs e)
        {
            string gamePath = Perferences.PathGame;
            if (!string.IsNullOrEmpty(gamePath) && File.Exists(gamePath))
            {
                try
                {
                    if (MessageBox.Show(Resources.AreYouReady, Resources.Dots, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation) != DialogResult.Retry)
                    {
                        Process.Start(gamePath);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteLog(ex);
                }
            }
            else
            {
                ShowMessage.Info(Resources.EmptyPath);
            }
        }

        private void miAbout_Click(object sender, EventArgs e)
        {
            AboutForm aboutForm = new AboutForm();
            aboutForm.ShowDialog();
        }
    }
}
